package com.peza.bikelog.gui.data;

import java.text.SimpleDateFormat;

import com.peza.bikelog.common.domain.LogEntry;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.ColumnGenerator;

public class DateColumnGenerator implements ColumnGenerator{

	private static final long serialVersionUID = 1L;

	@Override
	public Object generateCell(Table source, Object itemId, Object columnId) {
		if (itemId instanceof LogEntry){
			LogEntry entry = (LogEntry) itemId;
			String dateString = null;
			try {
				SimpleDateFormat dateFormatter = new SimpleDateFormat("dd MM yyyy");
				dateString = dateFormatter.format(entry.getDate().getTime());
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			}
			return dateString;
		}
		
		return "NaD";
	}

}
